package com.huawei.appgallery.downloadengine.api;

import android.net.NetworkInfo;
import android.os.Bundle;
import android.text.TextUtils;
import com.huawei.appgallery.foundation.storage.db.RecordBean;
import com.huawei.appmarket.service.activitydispatcher.OpenGateway.Param;
import com.huawei.hms.framework.common.ContainerUtils;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.Future;
import o.bmz;
import o.bnb;
import o.bnc;
import o.dmt;

public class SessionDownloadTask extends RecordBean {
    private static final Object EXTEND_LOCK = new Object();
    public static final String TABLE_NAME = "SessionDownloadTask";
    public static final String TAG = "SessionDownloadTask";
    private static long initialSessionId = System.currentTimeMillis();
    private static Object lock = new byte[0];
    private String accessId_;
    private boolean allowMobileNetworkDownload_;
    @EnableBundle
    private long alreadyDownloadSize_;
    @EnableBundle
    private String appID_;
    private int appType_;
    private boolean canFailToPause;
    private String cdnServerInfo;
    private bnb controller;
    private List<SessionDownloadTask> dependTaskList;
    @EnableBundle
    private String detailID_;
    private bmz diskSpacePolicy;
    private int dlPolicy_;
    private int dlType_;
    private c downloadQuality;
    private int downloadRate;
    private String extend_;
    private String extraParam_;
    private boolean failToPause;
    private String featureTitleResIds_;
    private boolean forceUseHttps;
    private Future<?> future;
    @EnableBundle
    private String iconUrl_;
    private String initParam_;
    @EnableBundle
    private int installType_;
    @EnableBundle
    public int interruptReason_;
    private boolean isForeGroundTask_;
    private boolean isInstant_;
    private volatile boolean isInterrupt;
    private volatile boolean isScheduled;
    private a lastDownloadErrInfo;
    private int maple_;
    @EnableBundle
    private String name_;
    @EnableBundle
    private String packageName_;
    private int packingType_;
    private int processorType_;
    @EnableBundle
    private int progress_;
    private int reportDownloadStartStatus_;
    private int serviceType_;
    @EnableBundle
    private long sessionId_;
    private boolean shouldShowNotification_;
    private String sliceCheckDataStringSha256_;
    private List<SplitTask> splitTaskList;
    @EnableBundle
    private int status_;
    private boolean suggestTryDownloadAgainInHttps;
    private Future<?> taskFuture;
    private int taskNet_;
    private long taskSubmitTime_;
    private long totalSize_;
    private String trace_;
    private String universalUrl_;
    @EnableBundle
    private int versionCode_;
    private String wishId_;
    private String wishWallReplyId_;

    public static class a {
        public int ˋ;
        public String ˎ;

        public String toString() {
            return this.ˋ + "-" + this.ˎ;
        }
    }

    public static class c {
        private String ˊ = "";
        private long ˋ;
        private long ˎ;
        private boolean ˏ = false;
        private String ॱ = "";

        public long ˏ() {
            return this.ˋ;
        }

        public void ॱ(long j) {
            this.ˋ = j;
        }

        public long ˎ() {
            return this.ˎ;
        }

        public void ˎ(long j) {
            this.ˎ = j;
        }

        public String ˋ() {
            return this.ॱ;
        }

        public boolean ॱ() {
            return this.ˏ;
        }

        public void ˎ(boolean z) {
            this.ˏ = z;
        }

        public void ˋ(NetworkInfo networkInfo) {
            if (networkInfo != null) {
                String subtypeName = networkInfo.getSubtypeName();
                if (subtypeName == null || subtypeName.length() <= 0) {
                    subtypeName = networkInfo.getTypeName();
                }
                if (!this.ˊ.equals(subtypeName)) {
                    this.ˊ = subtypeName;
                    this.ॱ += this.ˊ + "/";
                }
            }
        }
    }

    public SessionDownloadTask() {
        this.interruptReason_ = 0;
        this.packingType_ = 0;
        this.alreadyDownloadSize_ = 0;
        this.totalSize_ = 0;
        this.progress_ = 0;
        this.status_ = 0;
        this.splitTaskList = new ArrayList();
        this.dlType_ = 0;
        this.isInterrupt = false;
        this.taskFuture = null;
        this.installType_ = 0;
        this.accessId_ = null;
        this.initParam_ = null;
        this.extraParam_ = null;
        this.extend_ = null;
        this.dependTaskList = null;
        this.allowMobileNetworkDownload_ = false;
        this.taskSubmitTime_ = 0;
        this.suggestTryDownloadAgainInHttps = false;
        this.forceUseHttps = false;
        this.failToPause = false;
        this.canFailToPause = true;
        this.controller = null;
        this.reportDownloadStartStatus_ = 0;
        this.sliceCheckDataStringSha256_ = "";
        this.future = null;
        this.dlPolicy_ = 2;
        this.taskNet_ = 4;
        this.isScheduled = false;
        this.isInstant_ = false;
        this.appType_ = 1;
        this.shouldShowNotification_ = false;
        this.lastDownloadErrInfo = new a();
        this.downloadQuality = new c();
        this.sessionId_ = ꜞ();
    }

    private SessionDownloadTask(Bundle bundle) {
        int i = 0;
        this.interruptReason_ = 0;
        this.packingType_ = 0;
        this.alreadyDownloadSize_ = 0;
        this.totalSize_ = 0;
        this.progress_ = 0;
        this.status_ = 0;
        this.splitTaskList = new ArrayList();
        this.dlType_ = 0;
        this.isInterrupt = false;
        this.taskFuture = null;
        this.installType_ = 0;
        this.accessId_ = null;
        this.initParam_ = null;
        this.extraParam_ = null;
        this.extend_ = null;
        this.dependTaskList = null;
        this.allowMobileNetworkDownload_ = false;
        this.taskSubmitTime_ = 0;
        this.suggestTryDownloadAgainInHttps = false;
        this.forceUseHttps = false;
        this.failToPause = false;
        this.canFailToPause = true;
        this.controller = null;
        this.reportDownloadStartStatus_ = 0;
        this.sliceCheckDataStringSha256_ = "";
        this.future = null;
        this.dlPolicy_ = 2;
        this.taskNet_ = 4;
        this.isScheduled = false;
        this.isInstant_ = false;
        this.appType_ = 1;
        this.shouldShowNotification_ = false;
        this.lastDownloadErrInfo = new a();
        this.downloadQuality = new c();
        Field[] declaredFields = SessionDownloadTask.class.getDeclaredFields();
        while (i < declaredFields.length) {
            try {
                declaredFields[i].setAccessible(true);
                if (declaredFields[i].isAnnotationPresent(EnableBundle.class)) {
                    String simpleName = declaredFields[i].getType().getSimpleName();
                    String name = declaredFields[i].getName();
                    if (simpleName.equals(Param.TYPE_STR)) {
                        declaredFields[i].set(this, bundle.getString(name));
                    } else if (simpleName.equals(Param.TYPE_INT)) {
                        declaredFields[i].set(this, Integer.valueOf(bundle.getInt(name)));
                    } else if (simpleName.equals(Param.TYPE_LONG)) {
                        declaredFields[i].set(this, Long.valueOf(bundle.getLong(name)));
                    } else if (simpleName.equals(Param.TYPE_FLOAT)) {
                        declaredFields[i].set(this, Float.valueOf(bundle.getFloat(name)));
                    } else {
                        bnc.ˎ.ˊ("SessionDownloadTask", "unsupported field type:" + simpleName + HwAccountConstants.BLANK + declaredFields[i].getName());
                    }
                }
            } catch (Throwable e) {
                bnc.ˎ.ˊ("SessionDownloadTask", "SessionDownloadTask exception:", e);
            } catch (Throwable e2) {
                bnc.ˎ.ˊ("SessionDownloadTask", "SessionDownloadTask exception:", e2);
            }
            i++;
        }
    }

    public static SessionDownloadTask ˊ(Bundle bundle) {
        if (bundle == null) {
            return null;
        }
        return new SessionDownloadTask(bundle);
    }

    public int ॱ() {
        return this.serviceType_;
    }

    public void ˊ(int i) {
        this.serviceType_ = i;
    }

    public int ˋ() {
        return this.maple_;
    }

    public void ॱ(int i) {
        this.maple_ = i;
    }

    public String ˊ() {
        return this.wishWallReplyId_;
    }

    public void ˎ(String str) {
        this.wishWallReplyId_ = str;
    }

    public String ˎ() {
        return this.wishId_;
    }

    public void ˋ(String str) {
        this.wishId_ = str;
    }

    public boolean ʻ() {
        return this.isScheduled;
    }

    public void ॱ(boolean z) {
        this.isScheduled = z;
    }

    public boolean ʼ() {
        return this.isInstant_;
    }

    public void ˋ(boolean z) {
        this.isInstant_ = z;
    }

    public int ॱॱ() {
        return this.appType_;
    }

    public void ˎ(int i) {
        this.appType_ = i;
    }

    public boolean ʽ() {
        return this.shouldShowNotification_;
    }

    public void ˊ(boolean z) {
        this.shouldShowNotification_ = z;
    }

    public String ᐝ() {
        return this.universalUrl_;
    }

    public void ˊ(String str) {
        this.universalUrl_ = str;
    }

    public a ˏॱ() {
        return this.lastDownloadErrInfo;
    }

    public c ͺ() {
        return this.downloadQuality;
    }

    public String ॱˊ() {
        return this.detailID_;
    }

    public void ˏ(String str) {
        this.detailID_ = str;
    }

    public int ˊॱ() {
        return this.installType_;
    }

    public void ˏ(int i) {
        this.installType_ = i;
    }

    public int ʻॱ() {
        return this.processorType_;
    }

    public void ˋ(int i) {
        this.processorType_ = i;
    }

    public boolean ॱˎ() {
        return this.isForeGroundTask_;
    }

    public void ˎ(boolean z) {
        this.isForeGroundTask_ = z;
    }

    public int ᐝॱ() {
        return this.interruptReason_;
    }

    public void ʼ(int i) {
        this.interruptReason_ = i;
    }

    public int ॱᐝ() {
        return this.versionCode_;
    }

    public void ʻ(int i) {
        this.versionCode_ = i;
    }

    public String ॱˋ() {
        return this.appID_;
    }

    public void ॱ(String str) {
        this.appID_ = str;
    }

    public int ʽॱ() {
        return this.taskNet_;
    }

    public void ᐝ(int i) {
        this.taskNet_ = i;
    }

    public void ˏ(Bundle bundle) {
        Field[] declaredFields = SessionDownloadTask.class.getDeclaredFields();
        for (int i = 0; i < declaredFields.length; i++) {
            try {
                declaredFields[i].setAccessible(true);
                if (declaredFields[i].isAnnotationPresent(EnableBundle.class)) {
                    String simpleName = declaredFields[i].getType().getSimpleName();
                    String name = declaredFields[i].getName();
                    Object obj = declaredFields[i].get(this);
                    if (obj != null) {
                        if (simpleName.equals(Param.TYPE_STR)) {
                            bundle.putString(name, (String) obj);
                        } else if (simpleName.equals(Param.TYPE_INT)) {
                            bundle.putInt(name, ((Integer) obj).intValue());
                        } else if (simpleName.equals(Param.TYPE_LONG)) {
                            bundle.putLong(name, ((Long) obj).longValue());
                        } else if (simpleName.equals(Param.TYPE_FLOAT)) {
                            bundle.putFloat(name, ((Float) obj).floatValue());
                        } else if (simpleName.equals(Param.TYPE_BOOLEAN)) {
                            bundle.putBoolean(name, ((Boolean) obj).booleanValue());
                        } else {
                            bnc.ˎ.ˊ("SessionDownloadTask", "unsupport type");
                        }
                    }
                }
            } catch (Throwable e) {
                bnc.ˎ.ˊ("SessionDownloadTask", "writeToBundle exception:", e);
            } catch (Throwable e2) {
                bnc.ˎ.ˊ("SessionDownloadTask", "writeToBundle exception:", e2);
            }
        }
    }

    public int ˈ() {
        return this.status_;
    }

    public void ॱॱ(int i) {
        synchronized (this) {
            this.status_ = i;
        }
    }

    public long ʾ() {
        return this.sessionId_;
    }

    public void ˎ(long j) {
        this.sessionId_ = j;
    }

    public String ʿ() {
        return this.name_;
    }

    public void ॱॱ(String str) {
        this.name_ = str;
    }

    public int ʼॱ() {
        return this.progress_ > 100 ? 100 : this.progress_;
    }

    public void ʽ(int i) {
        this.progress_ = i;
    }

    public long ˋˊ() {
        return this.alreadyDownloadSize_;
    }

    public void ˏ(long j) {
        this.alreadyDownloadSize_ = j;
    }

    public long ˊˋ() {
        if (this.totalSize_ <= 0) {
            long j = 0;
            for (SplitTask splitTask : this.splitTaskList) {
                long ʼॱ;
                if (splitTask.ʾ() > 0) {
                    ʼॱ = splitTask.ʼॱ() + j;
                } else if (splitTask.ʻ() > 0) {
                    ʼॱ = splitTask.ʻ() + j;
                } else if (splitTask.ʼ() > 0) {
                    ʼॱ = splitTask.ʼ() + j;
                } else {
                    ʼॱ = j;
                }
                j = ʼॱ;
            }
            this.totalSize_ = j;
        }
        return this.totalSize_;
    }

    public void ॱ(long j) {
        this.totalSize_ = j;
    }

    public int ˉ() {
        return this.downloadRate;
    }

    public void ˏॱ(int i) {
        this.downloadRate = i;
    }

    public boolean ˊᐝ() {
        return this.isInterrupt;
    }

    public void ॱ(boolean z, int i) {
        synchronized (this) {
            this.isInterrupt = z;
            this.interruptReason_ = i;
            if (z) {
                this.downloadQuality.ˏ = true;
            }
            bnc.ˎ.ˋ("SessionDownloadTask", "setInterrupt,package:" + ˊˊ() + ", isInterrupt:" + z + ",reason:" + i);
            if (this.taskFuture != null) {
                try {
                    this.taskFuture.cancel(true);
                } catch (Throwable e) {
                    bnc.ˎ.ˊ("HiAppDownload", "DownloadTask internal cancel exception:", e);
                }
                this.taskFuture = null;
            }
        }
    }

    public synchronized void ˎ(Future<?> future) {
        this.taskFuture = future;
    }

    public String ˊˊ() {
        return this.packageName_;
    }

    public void ʼ(String str) {
        this.packageName_ = str;
    }

    public boolean ˍ() {
        return this.allowMobileNetworkDownload_;
    }

    public void ˏ(boolean z) {
        this.allowMobileNetworkDownload_ = z;
    }

    public String ˎˎ() {
        return this.iconUrl_;
    }

    public void ʽ(String str) {
        this.iconUrl_ = str;
    }

    public String t_() {
        return "SessionDownloadTask";
    }

    public String ˋᐝ() {
        return this.trace_;
    }

    public void ᐝ(String str) {
        this.trace_ = str;
    }

    public int ˌ() {
        return this.dlType_;
    }

    public void ˋॱ(int i) {
        this.dlType_ = i;
    }

    public long ˋˋ() {
        return this.taskSubmitTime_;
    }

    public void ˊ(long j) {
        this.taskSubmitTime_ = j;
    }

    public bmz ͺॱ() {
        return this.diskSpacePolicy;
    }

    public void ˋ(bmz o_bmz) {
        this.diskSpacePolicy = o_bmz;
    }

    public boolean ˎˏ() {
        return this.suggestTryDownloadAgainInHttps;
    }

    public boolean ˏˎ() {
        return this.failToPause;
    }

    public boolean ˏˏ() {
        return this.canFailToPause;
    }

    public void ʼ(boolean z) {
        this.canFailToPause = z;
    }

    public bnb ˑ() {
        return this.controller;
    }

    public void ˏ(bnb o_bnb) {
        this.controller = o_bnb;
    }

    public int ـ() {
        return this.reportDownloadStartStatus_;
    }

    public void ˊॱ(int i) {
        this.reportDownloadStartStatus_ = i;
    }

    public void a_(String str) {
        this.sliceCheckDataStringSha256_ = str;
    }

    public String ॱʽ() {
        return this.cdnServerInfo;
    }

    public void ˊॱ(String str) {
        this.cdnServerInfo = str;
    }

    public int ॱʻ() {
        return this.dlPolicy_;
    }

    public void ͺ(int i) {
        this.dlPolicy_ = i;
    }

    public String ॱͺ() {
        return this.accessId_;
    }

    public void ˋॱ(String str) {
        this.accessId_ = str;
    }

    public String ॱʼ() {
        return this.extraParam_;
    }

    public void ͺ(String str) {
        this.extraParam_ = str;
    }

    public String ᐨ() {
        return this.initParam_;
    }

    public void ˏॱ(String str) {
        this.initParam_ = str;
    }

    public String ᐧ() {
        return this.extend_;
    }

    public void ॱˊ(String str) {
        synchronized (EXTEND_LOCK) {
            if (this.extend_ == null) {
                this.extend_ = str;
            } else {
                this.extend_ += ContainerUtils.FIELD_DELIMITER + str;
            }
        }
    }

    public void ˎ(String str, String str2) {
        synchronized (EXTEND_LOCK) {
            Map ˊ = dmt.ˊ(this.extend_);
            if (str2 == null) {
                ˊ.remove(str);
            } else {
                ˊ.put(str, str2);
            }
            for (Entry entry : ˊ.entrySet()) {
                ॱˊ(((String) entry.getKey()) + ContainerUtils.KEY_VALUE_DELIMITER + ((String) entry.getValue()));
            }
        }
    }

    public String ॱˎ(String str) {
        if (TextUtils.isEmpty(this.extend_) || TextUtils.isEmpty(str)) {
            return null;
        }
        return (String) dmt.ˊ(this.extend_).get(str);
    }

    public String ᐝᐝ() {
        return this.featureTitleResIds_;
    }

    public void ʻॱ(String str) {
        this.featureTitleResIds_ = str;
    }

    public void ʽ(boolean z) {
    }

    public List<SessionDownloadTask> ᐝˋ() {
        return this.dependTaskList;
    }

    public void ॱ(List<SessionDownloadTask> list) {
        this.dependTaskList = list;
    }

    public void ˏ(SplitTask splitTask) {
        synchronized (this.splitTaskList) {
            this.splitTaskList.add(splitTask);
        }
    }

    public void ˎ(List<SplitTask> list) {
        synchronized (this.splitTaskList) {
            this.splitTaskList.addAll(list);
        }
    }

    public List<SplitTask> ᐝˊ() {
        return this.splitTaskList;
    }

    public int ꓸ() {
        return this.packingType_;
    }

    public void ॱˊ(int i) {
        this.packingType_ = i;
    }

    public boolean ꜟ() {
        return this.packingType_ == 1;
    }

    private static long ꜞ() {
        long j;
        synchronized (lock) {
            initialSessionId++;
            if (initialSessionId == Long.MAX_VALUE) {
                initialSessionId = 0;
            }
            j = initialSessionId;
        }
        return j;
    }
}
